// 将缺4的十进制 改为正确的数字, 也就是只有9进制
// 可以遍历每个位置, 分别乘以9的0, 9的1; 同时, 大于4的要减一
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let num;
rl.on("line", (line)=>{
    if(num === undefined) {
        num = line.trim() // 字符串
        console.log(getResult(num))

        // clear
        num = undefined
    }

})

/**
 *
 * @param num {string} 数字字符串
 */
function getResult(num) {
    let result = 0;
    for (let i = num.length - 1; i >= 0 ; i--) {
        let number = Number(num[i])
        if(number > 4) {
            number--
        }
        result += number * Math.pow(9, num.length - i - 1)
    }
    return result
}
